package com.sky.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sky.domain.EnvironmentalKnowledge;
import com.sky.dto.EnvironmentalKnowledePageDto;
import com.sky.mapper.EnvironmentalKnowledgeMapper;
import com.sky.service.EnvironmentalKnowledgeService;
import com.sky.vo.DataGridView;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author majinan
 */
@Service
public class EnvironmentalKnowledgeServiceImpl implements EnvironmentalKnowledgeService {


    @Autowired
    private EnvironmentalKnowledgeMapper mapper;

    @Override
    public EnvironmentalKnowledge selectEnvironmentById(Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public DataGridView selectList(EnvironmentalKnowledePageDto dto) {
        Page<EnvironmentalKnowledge> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        QueryWrapper<EnvironmentalKnowledge> qw = new QueryWrapper<>();
//         查询条件
        qw.like(StringUtils.isNotBlank(dto.getTitle()), EnvironmentalKnowledge.TITLE,dto.getTitle());
        qw.like(StringUtils.isNotBlank(dto.getCreateByName()), EnvironmentalKnowledge.CREATE_BY_USERNAME,dto.getCreateByName());
        qw.like(StringUtils.isNotBlank(dto.getCreateByUser()), EnvironmentalKnowledge.CREATE_BY_USER,dto.getCreateByUser());
        this.mapper.selectPage(page,qw);
        return new DataGridView(page.getTotal(),page.getRecords());
    }
}
